/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iie.tools;

import java.io.ByteArrayInputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;

/**
 *
 * @author zhangyun
 */
public class JettyTools {

    private static Logger logger = Logger.getLogger(JettyTools.class);

    public static void send(String xml) {
        try {
            String sysControllerIP = PropsFiles.getValue("serverIP");
            String jettyPath = PropsFiles.getValue("jettyPath");
            logger.info("the serverIP is " + sysControllerIP + " and the jettyPath is " + jettyPath);
            HttpClient httpClient = new DefaultHttpClient();
            String path = "http://" + sysControllerIP + jettyPath;
            logger.info("the request path is " + path);
            HttpPost httppost = new HttpPost(path);
            //HttpPost httppost = new HttpPost("http://" + sysControllerIP + jettyPath);
            //HttpPost httppost = new HttpPost("http://" + sysControllerIP + "/resources/clsagent/report");
            InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(xml.getBytes()), -1);
            reqEntity.setContentType("binary/octet-stream");
            reqEntity.setChunked(true);
            httppost.setEntity(reqEntity);
            try {
                HttpResponse response = httpClient.execute(httppost);
                int cc = 0;
            } catch (Exception e) {
                logger.error("jetty can not send 1!");
                logger.debug("Jetty client send message err!" + e);
            }
            httppost.releaseConnection();
        } catch (Exception ex) {
            logger.error("jetty can not send 2!");
            logger.debug("jetty send error. " + "|" + ex.getLocalizedMessage() + "|" + ex.getMessage() + "|" + ex.getStackTrace(), ex);
        }
    }
}
